package cn.edu.hitwh.service.test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BaseFont;

public class HTML2PDF {

	public static void main(String[] args) {
		
        ITextRenderer renderer = new ITextRenderer();     
       
        try {
			renderer.setDocument(new File("C:/Users/LVZY/Desktop/Zhao/resumes/test.html").toURI().toURL().toString());
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}   
        
        // 解决中文支持问题     
        ITextFontResolver fontResolver = renderer.getFontResolver();    
        try {
			fontResolver.addFont("C:/Windows/Fonts/msyh.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
		} catch (DocumentException | IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}   
        
        
        renderer.layout();    
        try {
			renderer.createPDF(new FileOutputStream("pdf_3.pdf"));
		} catch (DocumentException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
 
        System.out.println( "PDF Created!" );
	}

}
